package org.shop.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.shop.dao.ShoppingTrolleyMapper;
import org.shop.entity.ShoppingTrolley;
import org.shop.service.ShoppingCardService;
import org.shop.service.base.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ShoppingCardServiceImpl extends BaseServiceImpl<ShoppingTrolley, Long> implements ShoppingCardService{

	@Autowired
    private ShoppingTrolleyMapper shoppingTrolleyMapper;
    
	@Override
	public List<Map<String,Object>> getShoppingCardList(Map<String, Object> params) {
		List<Map<String, Object>> merchantList = shoppingTrolleyMapper.getMerchantList(params);
		List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
		for(int i=0;i<merchantList.size();i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			Map<String, Object> params2 = new HashMap<String, Object>();
			params2.put("userId", params.get("userId"));
			params2.put("userCheck", params.get("userCheck"));
			params2.put("merchantId", merchantList.get(i).get("merchantId"));
			map = merchantList.get(i);
			List<Map<String,Object>> shoppingGoodsList = shoppingTrolleyMapper.getShoppingCardList(params2);
			map.put("shoppingGoodsList", shoppingGoodsList);
			list.add(map);
		}
		return list;
//		return shoppingTrolleyMapper.getShoppingCardList(params);
	}
	@Override
	public ShoppingTrolley getShoppingCardGoods(Map<String, Object> params) {
		return shoppingTrolleyMapper.getShoppingCardGoods(params);
	}
	@Override
	public int updateShoppingCardGoods(Map<String, Object> params) {
		return shoppingTrolleyMapper.updateShoppingCardGoods(params);
	}
	@Override
	public int delShoppingCardGoods(Map<String, Object> params) {
		return shoppingTrolleyMapper.delShoppingCardGoods(params);
	}

	@Override
	public List<Map<String,Object>> getCheckShoppingCardList(Map<String, Object> params) {
		List<Map<String, Object>> list = shoppingTrolleyMapper.getShoppingCardList(params);
		return list;
	}
	@Override
	public int getMyShoppingCount(Long usersId) {
		return shoppingTrolleyMapper.getMyShoppingCount(usersId);
	}
}
